home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Leser 15 / Amiga Plus Leser CD 15.iso / Tools / Development / MosaicSRC / src / HTMLimages.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-03-13  |  18.7 KB  |  784 lines

  1. // MDF - PORT FROM NCSA VERSION 2.1
  2.  
  3. /****************************************************************************
  4.  * NCSA Mosaic for the X Window System                                      *
  5.  * Software Development Group                                               *
  6.  * National Center for Supercomputing Applications                          *
  7.  * University of Illinois at Urbana-Champaign                               *
  8.  * 605 E. Springfield, Champaign IL 61820                                   *
  9.  * mosaic@ncsa.uiuc.edu                                                     *
  10.  *                                                                          *
  11.  * Copyright (C) 1993, Board of Trustees of the University of Illinois      *
  12.  *                                                                          *
  13.  * NCSA Mosaic software, both binary and source (hereafter, Software) is    *
  14.  * copyrighted by The Board of Trustees of the University of Illinois       *
  15.  * (UI), and ownership remains with the UI.                                 *
  16.  *                                                                          *
  17.  * The UI grants you (hereafter, Licensee) a license to use the Software    *
  18.  * for academic, research and internal business purposes only, without a    *
  19.  * fee.  Licensee may distribute the binary and source code (if released)   *
  20.  * to third parties provided that the copyright notice and this statement   *
  21.  * appears on all copies and that no charge is associated with such         *
  22.  * copies.                                                                  *
  23.  *                                                                          *
  24.  * Licensee may make derivative works.  However, if Licensee distributes    *
  25.  * any derivative work based on or derived from the Software, then          *
  26.  * Licensee will (1) notify NCSA regarding its distribution of the          *
  27.  * derivative work, and (2) clearly notify users that such derivative       *
  28.  * work is a modified version and not the original NCSA Mosaic              *
  29.  * distributed by the UI.                                                   *
  30.  *                                                                          *
  31.  * Any Licensee wishing to make commercial use of the Software should       *
  32.  * contact the UI, c/o NCSA, to negotiate an appropriate license for such   *
  33.  * commercial use.  Commercial use includes (1) integration of all or       *
  34.  * part of the source code into a product for sale or license by or on      *
  35.  * behalf of Licensee to third parties, or (2) distribution of the binary   *
  36.  * code or source code to third parties that need it to utilize a           *
  37.  * commercial product sold or licensed by or on behalf of Licensee.         *
  38.  *                                                                          *
  39.  * UI MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE FOR   *
  40.  * ANY PURPOSE.  IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED          *
  41.  * WARRANTY.  THE UI SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY THE    *
  42.  * USERS OF THIS SOFTWARE.                                                  *
  43.  *                                                                          *
  44.  * By using or copying this Software, Licensee agrees to abide by the       *
  45.  * copyright law and all other applicable laws of the U.S. including, but   *
  46.  * not limited to, export control laws, and the terms of this license.      *
  47.  * UI shall have the right to terminate this license immediately by         *
  48.  * written notice upon Licensee's breach of, or non-compliance with, any    *
  49.  * of its terms.  Licensee may be held legally responsible for any          *
  50.  * copyright infringement that is caused or encouraged by Licensee's        *
  51.  * failure to abide by the terms of this license.                           *
  52.  *                                                                          *
  53.  * Comments and questions are welcome and can be sent to                    *
  54.  * mosaic-x@ncsa.uiuc.edu.                                                  *
  55.  ****************************************************************************/
  56.  
  57. #ifdef _AMIGA
  58. #include <exec/types.h>
  59. #include <stdlib.h>
  60. #include <string.h>
  61. #include <intuition/intuitionbase.h>
  62. #include <clib/graphics_protos.h>
  63. #include <graphics/gfxmacros.h>
  64. #include "XtoI.h"
  65. extern struct Library *GfxBase;
  66. #endif
  67.  
  68. #include <stdio.h>
  69. #include <ctype.h>
  70. /* None of these functions can be called outside the html widget */
  71. #include "HTMLP.h"
  72. #include "NoImage.xbm"
  73. #include "DelayedImage.xbm"
  74. #include "AnchoredImage.xbm"
  75.  
  76.  
  77. #define IMAGE_BORDER    1
  78.  
  79.  
  80. ImageInfo no_image;
  81. ImageInfo delayed_image;
  82. ImageInfo anchored_image;
  83.  
  84. static int allocation_index[256];
  85.  
  86. /* MDF - Special function to create an Amiga BitMap from some bits in
  87.    a header file.  The header file must first be converted from XBM format
  88.    to an Amiga compatible format! */
  89. Pixmap CreateBitMapFromData(UBYTE *bits, int width, int height, int depth)
  90. {
  91.   struct BitMap *bm;
  92.   PLANEPTR p, s;
  93.   int i;
  94.  
  95.   bm = AllocBitMap(width, height, depth, BMF_CLEAR, NULL);
  96.  
  97.   p = bm->Planes[0];
  98.   s = bits;
  99.  
  100.   for (i = 0; i < bm->BytesPerRow * height; i++) {
  101.     *p++ = *s++;
  102.   }
  103.  
  104.   return bm;
  105. }
  106.  
  107.  
  108. Pixmap CreateBitMapFromXBMData(UBYTE *bits, int width, int height, int depth)
  109. {
  110.   struct BitMap *bm;
  111.   PLANEPTR d, s;
  112.   int i, j, z1, z2;
  113.   int bytes_per_line;
  114.   UBYTE b1, b2;
  115.  
  116.   bm = AllocBitMap(width, height, depth, BMF_CLEAR, NULL);
  117.  
  118.   d = bm->Planes[0];
  119.   s = bits;
  120.  
  121.   bytes_per_line = ((width + 7) / 8);
  122.  
  123.   for (i=0; i<height; i++) {
  124.     for (j=0; j<bytes_per_line; j++) {
  125.       b1 = *s++;
  126.       b2 = 0;
  127.       for (z1 = 128, z2 = 1; z2 < 250; z1 /= 2, z2 *= 2) {
  128.     if (b1 >= z1) {
  129.       b1 = b1 - z1;
  130.       b2 = b2 + z2;
  131.     }    
  132.       }
  133.       *d++ = b2;
  134.     }
  135.     if ((bytes_per_line) != bm->BytesPerRow) *d++ = 0;
  136.   }
  137.   return bm;
  138. }
  139.  
  140.  
  141. /*
  142.  * Free all the colors in the default colormap that we have allocated so far.
  143.  */
  144. void
  145. FreeColors(void *dsp, void *colormap)
  146. {
  147. #ifndef _AMIGA
  148.     int i, j;
  149.     unsigned long pix;
  150.  
  151.     for (i=0; i<256; i++)
  152.     {
  153.         if (allocation_index[i])
  154.         {
  155.             pix = (unsigned long)i;
  156.             /*
  157.              * Because X is stupid, we have to Free the color
  158.              * once for each time we've allocated it.
  159.              */
  160.             for (j=0; j<allocation_index[i]; j++)
  161.             {
  162.                 XFreeColors(dsp, colormap, &pix, 1, 0L);
  163.             }
  164.         }
  165.         allocation_index[i] = 0;
  166.     }
  167. #endif /* _AMIGA */
  168. }
  169.  
  170.  
  171. /*
  172.  * Free up all the pixmaps allocated for this document.
  173.  */
  174. void
  175. FreeImages(HTMLGadClData * hw)
  176. {
  177.     struct ele_rec *eptr;
  178.  
  179.     eptr = hw->formatted_elements;
  180.     while (eptr != NULL)
  181.     {
  182.         if ((eptr->type == E_IMAGE)&&(eptr->pic_data != NULL))
  183.         {
  184.             /*
  185.              * Don't free the no_image default image
  186.              */
  187.             if ((eptr->pic_data->image != (Pixmap)NULL)&&
  188.                 (eptr->pic_data->image != delayed_image.image)&&
  189.                 (eptr->pic_data->image != anchored_image.image)&&
  190.                 (eptr->pic_data->image != no_image.image))
  191.             {
  192.                 /*
  193.                  * Don't free internal images
  194.                  */
  195.                 if ((eptr->edata != NULL)&&
  196.                     (strncmp(eptr->edata, INTERNAL_IMAGE,
  197.                     strlen(INTERNAL_IMAGE)) == 0))
  198.                 {
  199.                 }
  200.                 else
  201.                 {
  202.                   WaitBlit();
  203.                   FreeBitMap(eptr->pic_data->image);
  204. //                    XFreePixmap(XtDisplay(hw),
  205. //                        eptr->pic_data->image);
  206.                     eptr->pic_data->image = (Pixmap)NULL;
  207.                 }
  208.             }
  209.         }
  210.         eptr = eptr->next;
  211.     }
  212. }
  213.  
  214.  
  215. #ifndef _AMIGA
  216. /*
  217.  * Find the closest color by allocating it, or picking an already allocated
  218.  * color
  219.  */
  220. void
  221. FindColor(dsp, colormap, colr)
  222.     Display *dsp;
  223.     Colormap colormap;
  224.     XColor *colr;
  225. {
  226.     int i, match;
  227. #ifdef MORE_ACCURATE
  228.     double rd, gd, bd, dist, mindist;
  229. #else
  230.     int rd, gd, bd, dist, mindist;
  231. #endif /* MORE_ACCURATE */
  232.     int cindx;
  233. static XColor def_colrs[256];
  234. static int have_colors = 0;
  235.     int NumCells;
  236.  
  237.     match = XAllocColor(dsp, colormap, colr);
  238.     if (match == 0)
  239.     {
  240.         NumCells = DisplayCells(dsp, DefaultScreen(dsp));
  241.         if (!have_colors)
  242.         {
  243.             for (i=0; i<NumCells; i++)
  244.             {
  245.                 def_colrs[i].pixel = i;
  246.             }
  247.             XQueryColors(dsp, colormap, def_colrs, NumCells);
  248.             have_colors = 1;
  249.         }
  250. #ifdef MORE_ACCURATE
  251.         mindist = 196608.0;        /* 256.0 * 256.0 * 3.0 */
  252.         cindx = colr->pixel;
  253.         for (i=0; i<NumCells; i++)
  254.         {
  255.             rd = (def_colrs[i].red - colr->red) / 256.0;
  256.             gd = (def_colrs[i].green - colr->green) / 256.0;
  257.             bd = (def_colrs[i].blue - colr->blue) / 256.0;
  258.             dist = (rd * rd) +
  259.                 (gd * gd) +
  260.                 (bd * bd);
  261.             if (dist < mindist)
  262.             {
  263.                 mindist = dist;
  264.                 cindx = def_colrs[i].pixel;
  265.                 if (dist == 0.0)
  266.                 {
  267.                     break;
  268.                 }
  269.             }
  270.         }
  271. #else
  272.         mindist = 196608;        /* 256 * 256 * 3 */
  273.         cindx = colr->pixel;
  274.         for (i=0; i<NumCells; i++)
  275.         {
  276.             rd = ((int)(def_colrs[i].red >> 8) -
  277.                 (int)(colr->red >> 8));
  278.             gd = ((int)(def_colrs[i].green >> 8) -
  279.                 (int)(colr->green >> 8));
  280.             bd = ((int)(def_colrs[i].blue >> 8) -
  281.                 (int)(colr->blue >> 8));
  282.             dist = (rd * rd) +
  283.                 (gd * gd) +
  284.                 (bd * bd);
  285.             if (dist < mindist)
  286.             {
  287.                 mindist = dist;
  288.                 cindx = def_colrs[i].pixel;
  289.                 if (dist == 0)
  290.                 {
  291.                     break;
  292.                 }
  293.             }
  294.         }
  295. #endif /* MORE_ACCURATE */
  296.         colr->pixel = cindx;
  297.         colr->red = def_colrs[cindx].red;
  298.         colr->green = def_colrs[cindx].green;
  299.         colr->blue = def_colrs[cindx].blue;
  300.     }
  301.     else
  302.     {
  303.         /*
  304.          * Keep a count of how many times we have allocated the
  305.          * same color, so we can properly free them later.
  306.          */
  307.         allocation_index[colr->pixel]++;
  308.  
  309.         /*
  310.          * If this is a new color, we've actually changed the default
  311.          * colormap, and may have to re-query it later.
  312.          */
  313.         if (allocation_index[colr->pixel] == 1)
  314.         {
  315.             have_colors = 0;
  316.         }
  317.     }
  318. }
  319. #endif /* _AMIGA */
  320.  
  321.  
  322. #ifndef _AMIGA
  323. /*
  324.  * Make am image of appropriate depth for display from image data.
  325.  */
  326. XImage *
  327. MakeImage(dsp, data, width, height, depth, img_info)
  328.     Display *dsp;
  329.     unsigned char *data;
  330.     int width, height;
  331.     int depth;
  332.     ImageInfo *img_info;
  333. {
  334.     int linepad, shiftnum;
  335.     int shiftstart, shiftstop, shiftinc;
  336.     int bytesperline;
  337.     int temp;
  338.     int w, h;
  339.     XImage *newimage;
  340.     unsigned char *bit_data, *bitp, *datap;
  341.  
  342.     switch(depth)
  343.     {
  344.         case 6:
  345.         case 8:
  346.         bit_data = (unsigned char *)malloc(width * height);
  347.         bcopy(data, bit_data, (width * height));
  348.         bytesperline = width;
  349.         newimage = XCreateImage(dsp,
  350.             DefaultVisual(dsp, DefaultScreen(dsp)),
  351.             depth, ZPixmap, 0, (char *)bit_data,
  352.             width, height, 8, bytesperline);
  353.         break;
  354.         case 1:
  355.         case 2:
  356.         case 4:
  357.         if (BitmapBitOrder(dsp) == LSBFirst)
  358.         {
  359.             shiftstart = 0;
  360.             shiftstop = 8;
  361.             shiftinc = depth;
  362.         }
  363.         else
  364.         {
  365.             shiftstart = 8 - depth;
  366.             shiftstop = -depth;
  367.             shiftinc = -depth;
  368.         }
  369.         linepad = 8 - (width % 8);
  370.         bit_data = (unsigned char *)malloc(((width + linepad) * height)
  371.                 + 1);
  372.         bitp = bit_data;
  373.         datap = data;
  374.         *bitp = 0;
  375.         shiftnum = shiftstart;
  376.         for (h=0; h<height; h++)
  377.         {
  378.             for (w=0; w<width; w++)
  379.             {
  380.                 temp = *datap++ << shiftnum;
  381.                 *bitp = *bitp | temp;
  382.                 shiftnum = shiftnum + shiftinc;
  383.                 if (shiftnum == shiftstop)
  384.                 {
  385.                     shiftnum = shiftstart;
  386.                     bitp++;
  387.                     *bitp = 0;
  388.                 }
  389.             }
  390.             for (w=0; w<linepad; w++)
  391.             {
  392.                 shiftnum = shiftnum + shiftinc;
  393.                 if (shiftnum == shiftstop)
  394.                 {
  395.                     shiftnum = shiftstart;
  396.                     bitp++;
  397.                     *bitp = 0;
  398.                 }
  399.             }
  400.         }
  401.         bytesperline = (width + linepad) * depth / 8;
  402.         newimage = XCreateImage(dsp,
  403.             DefaultVisual(dsp, DefaultScreen(dsp)),
  404.             depth, ZPixmap, 0, (char *)bit_data,
  405.             (width + linepad), height, 8, bytesperline);
  406.         break;
  407.         /*
  408.          * WARNING:  This depth 16 code is donated code for 16 but
  409.          * TrueColor displays.  I have no access to such displays, so I
  410.          * can't really test it.
  411.          * Donated by - andrew@icarus.demon.co.uk
  412.          */
  413.         case 16:
  414.         bit_data = (unsigned char *)malloc(width * height * 2);
  415.         bitp = bit_data;
  416.         datap = data;
  417.         for (w = (width * height); w > 0; w--)
  418.         {
  419.             temp = (((img_info->reds[(int)*datap] >> 1)& 0x7c00) |
  420.                 ((img_info->greens[(int)*datap] >> 6)& 0x03e0) |
  421.                 ((img_info->blues[(int)*datap] >> 11)& 0x001f));
  422.  
  423.             if (BitmapBitOrder(dsp) == MSBFirst)
  424.             {
  425.                 *bitp++ = (temp >> 8) & 0xff;
  426.                 *bitp++ = temp & 0xff;
  427.             }
  428.             else
  429.             {
  430.                 *bitp++ = temp & 0xff;
  431.                 *bitp++ = (temp >> 8) & 0xff;
  432.             }
  433.  
  434.             datap++;
  435.         }
  436.  
  437.         newimage = XCreateImage(dsp,
  438.             DefaultVisual(dsp, DefaultScreen(dsp)),
  439.             depth, ZPixmap, 0, (char *)bit_data,
  440.             width, height, 16, 0);
  441.         break;
  442.         case 24:
  443.         bit_data = (unsigned char *)malloc(width * height * 4);
  444.  
  445.         if (BitmapBitOrder(dsp) == MSBFirst)
  446.         {
  447.             bitp = bit_data;
  448.             datap = data;
  449.             for (w = (width * height); w > 0; w--)
  450.             {
  451.                 *bitp++ = (unsigned char)0;
  452.                 *bitp++ = (unsigned char)
  453.                     ((img_info->blues[(int)*datap]>>8) &
  454.                     0xff);
  455.                 *bitp++ = (unsigned char)
  456.                     ((img_info->greens[(int)*datap]>>8) &
  457.                     0xff);
  458.                 *bitp++ = (unsigned char)
  459.                     ((img_info->reds[(int)*datap]>>8) &
  460.                     0xff);
  461.                 datap++;
  462.             }
  463.         }
  464.         else
  465.         {
  466.             bitp = bit_data;
  467.             datap = data;
  468.             for (w = (width * height); w > 0; w--)
  469.             {
  470.                 *bitp++ = (unsigned char)
  471.                     ((img_info->reds[(int)*datap]>>8) &
  472.                     0xff);
  473.                 *bitp++ = (unsigned char)
  474.                     ((img_info->greens[(int)*datap]>>8) &
  475.                     0xff);
  476.                 *bitp++ = (unsigned char)
  477.                     ((img_info->blues[(int)*datap]>>8) &
  478.                     0xff);
  479.                 *bitp++ = (unsigned char)0;
  480.                 datap++;
  481.             }
  482.         }
  483.  
  484.         newimage = XCreateImage(dsp,
  485.             DefaultVisual(dsp, DefaultScreen(dsp)),
  486.             depth, ZPixmap, 0, (char *)bit_data,
  487.             width, height, 32, 0);
  488.         break;
  489.         default:
  490.         fprintf(stderr, "Don't know how to format image for display of depth %d\n", depth);
  491.         return(NULL);
  492.     }
  493.  
  494.     return(newimage);
  495. }
  496. #endif /* _AMIGA */
  497.  
  498.  
  499. int
  500. AnchoredHeight(HTMLGadClData * hw)
  501. {
  502.     return((int)(AnchoredImage_height + IMAGE_BORDER));
  503. }
  504.  
  505.  
  506. char *
  507. IsMapForm(HTMLGadClData * hw)
  508. {
  509.     char *str;
  510.  
  511.     str = (char *)malloc(strlen("ISMAP Form") + 1);
  512.     if (str != NULL)
  513.     {
  514.         strcpy(str, "ISMAP Form");
  515.     }
  516.     return(str);
  517. }
  518.  
  519.  
  520. int
  521. IsIsMapForm(HTMLGadClData * hw, char *href)
  522. {
  523.     if ((href != NULL)&&(strcmp(href, "ISMAP Form") == 0))
  524.     {
  525.         return(1);
  526.     }
  527.     else
  528.     {
  529.         return(0);
  530.     }
  531. }
  532.  
  533.  
  534. char *
  535. DelayedHRef(HTMLGadClData * hw)
  536. {
  537.     char *str;
  538.  
  539.     str = (char *)malloc(strlen("Delayed Image") + 1);
  540.     if (str != NULL)
  541.     {
  542.         strcpy(str, "Delayed Image");
  543.     }
  544.     return(str);
  545. }
  546.  
  547.  
  548. int
  549. IsDelayedHRef(HTMLGadClData * hw, char *href)
  550. {
  551.     if ((href != NULL)&&(strcmp(href, "Delayed Image") == 0))
  552.     {
  553.         return(1);
  554.     }
  555.     else
  556.     {
  557.         return(0);
  558.     }
  559. }
  560.  
  561.  
  562. /* MDF - Heavily hacked */
  563. Pixmap
  564. DelayedImage(HTMLGadClData * hw, Boolean anchored)
  565. {
  566.     if (delayed_image.image == (Pixmap)NULL)
  567.     {
  568.             delayed_image.image = CreateBitMapFromData(DelayedImage_bits,
  569.                   DelayedImage_width,
  570.                   DelayedImage_height,
  571.                   hw->rp->BitMap->Depth);
  572.     }
  573.  
  574.     if ((anchored == True)&&(anchored_image.image == (Pixmap)NULL))
  575.     {
  576.         Pixmap pix;
  577.  
  578.             anchored_image.image = CreateBitMapFromXBMData(AnchoredImage_bits,
  579.                   AnchoredImage_width,
  580.                   AnchoredImage_height,
  581.                   hw->rp->BitMap->Depth);
  582.         pix = AllocBitMap(DelayedImage_width,
  583.                   DelayedImage_height + AnchoredImage_height +
  584.                       IMAGE_BORDER,
  585.                   hw->rp->BitMap->Depth, BMF_CLEAR, NULL);
  586.         BltBitMap(anchored_image.image, 0, 0,
  587.               pix, 0, 0,
  588.               AnchoredImage_width, AnchoredImage_height,
  589.               0xc0, 0xff, NULL);
  590.         BltBitMap(delayed_image.image, 0, 0,
  591.               pix, 0, AnchoredImage_height + IMAGE_BORDER,
  592.               DelayedImage_width, DelayedImage_height,
  593.               0xc0, 0xff, NULL);
  594.         FreeBitMap(anchored_image.image);
  595.  
  596.         anchored_image.image = pix;
  597.  
  598.         return(anchored_image.image);
  599.     }
  600.  
  601.     return(delayed_image.image);
  602. }
  603.  
  604.  
  605. ImageInfo *
  606. DelayedImageData(HTMLGadClData * hw, Boolean anchored)
  607. {
  608.     delayed_image.delayed = 1;
  609.     delayed_image.internal = 0;
  610.     delayed_image.fetched = 0;
  611.     delayed_image.width = DelayedImage_width;
  612.     delayed_image.height = DelayedImage_height;
  613.     delayed_image.num_colors = 0;
  614.     delayed_image.reds = NULL;
  615.     delayed_image.greens = NULL;
  616.     delayed_image.blues = NULL;
  617.     delayed_image.image_data = NULL;
  618.     delayed_image.image = (Pixmap)NULL;
  619.  
  620.     if (anchored == True)
  621.     {
  622.         anchored_image.delayed = 0;
  623.         anchored_image.internal = 0;
  624.         anchored_image.fetched = 0;
  625.         anchored_image.width = DelayedImage_width;
  626.         anchored_image.height = DelayedImage_height +
  627.             AnchoredImage_height + IMAGE_BORDER;
  628.         anchored_image.num_colors = 0;
  629.         anchored_image.reds = NULL;
  630.         anchored_image.greens = NULL;
  631.         anchored_image.blues = NULL;
  632.         anchored_image.image_data = NULL;
  633.         anchored_image.image = (Pixmap)NULL;
  634.  
  635.         return(&anchored_image);
  636.     }
  637.  
  638.     return(&delayed_image);
  639. }
  640.  
  641.  
  642. Pixmap
  643. NoImage(HTMLGadClData * hw)
  644. {
  645.     if (no_image.image == (Pixmap)NULL)
  646.     {
  647.       no_image.image = CreateBitMapFromData(NoImage_bits,
  648.                   NoImage_width,
  649.                   NoImage_height,
  650.                   hw->rp->BitMap->Depth);
  651.     }
  652.     return(no_image.image);
  653. }
  654.  
  655.  
  656. ImageInfo *
  657. NoImageData(HTMLGadClData * hw)
  658. {
  659.     no_image.delayed = 0;
  660.     no_image.internal = 0;
  661.     no_image.fetched = 0;
  662.     no_image.width = NoImage_width;
  663.     no_image.height = NoImage_height;
  664.     no_image.num_colors = 0;
  665.     no_image.reds = NULL;
  666.     no_image.greens = NULL;
  667.     no_image.blues = NULL;
  668.     no_image.image_data = NULL;
  669.     no_image.image = (Pixmap)NULL;
  670.  
  671.     return(&no_image);
  672. }
  673.  
  674.  
  675. Pixmap
  676. InfoToImage(HTMLGadClData * hw, ImageInfo *img_info)
  677. {
  678. #ifndef _AMIGA
  679.     int i, size;
  680.     Pixmap Img;
  681.     XImage *tmpimage;
  682.     XColor tmpcolr;
  683.     int *Mapping;
  684.     unsigned char *tmpdata;
  685.     unsigned char *ptr;
  686.     unsigned char *ptr2;
  687.     int Vclass;
  688.     XVisualInfo vinfo, *vptr;
  689.  
  690.     /* find the visual class. */
  691.     vinfo.visualid = XVisualIDFromVisual(DefaultVisual(XtDisplay(hw),
  692.         DefaultScreen(XtDisplay(hw))));
  693.     vptr = XGetVisualInfo(XtDisplay(hw), VisualIDMask, &vinfo, &i);
  694.     Vclass = vptr->class;
  695.     XFree((char *)vptr);
  696.  
  697.     Mapping = (int *)malloc(img_info->num_colors * sizeof(int));
  698.  
  699.     for (i=0; i < img_info->num_colors; i++)
  700.     {
  701.         tmpcolr.red = img_info->reds[i];
  702.         tmpcolr.green = img_info->greens[i];
  703.         tmpcolr.blue = img_info->blues[i];
  704.         tmpcolr.flags = DoRed|DoGreen|DoBlue;
  705.         if (Vclass == TrueColor)
  706.         {
  707.             Mapping[i] = i;
  708.         }
  709.         else
  710.         {
  711.             FindColor(XtDisplay(hw),
  712.                 DefaultColormapOfScreen(XtScreen(hw)),
  713.                 &tmpcolr);
  714.             Mapping[i] = tmpcolr.pixel;
  715.         }
  716.     }
  717.  
  718.     size = img_info->width * img_info->height;
  719.     if (size == 0)
  720.     {
  721.         tmpdata = NULL;
  722.     }
  723.     else
  724.     {
  725.         tmpdata = (unsigned char *)malloc(size);
  726.     }
  727.     if (tmpdata == NULL)
  728.     {
  729.         tmpimage = NULL;
  730.         Img = (Pixmap)NULL;
  731.     }
  732.     else
  733.     {
  734.         ptr = img_info->image_data;
  735.         ptr2 = tmpdata;
  736.         for (i=0; i < size; i++)
  737.         {
  738.             *ptr2++ = (unsigned char)Mapping[(int)*ptr];
  739.             ptr++;
  740.         }
  741.  
  742.         tmpimage = MakeImage(XtDisplay(hw), tmpdata,
  743.             img_info->width, img_info->height,
  744.             DefaultDepthOfScreen(XtScreen(hw)), img_info);
  745.  
  746.                 /* Caught by Purify; should be OK. */
  747.                 free (tmpdata);
  748.  
  749.         Img = XCreatePixmap(XtDisplay(hw->view),
  750.             XtWindow(hw->view),
  751.             img_info->width, img_info->height,
  752.             DefaultDepthOfScreen(XtScreen(hw)));
  753.     }
  754.  
  755.     if ((tmpimage == NULL)||(Img == (Pixmap)NULL))
  756.     {
  757.         if (tmpimage != NULL)
  758.         {
  759.             XDestroyImage(tmpimage);
  760.         }
  761.         if (Img != (Pixmap)NULL)
  762.         {
  763.             XFreePixmap(XtDisplay(hw), Img);
  764.         }
  765.         img_info->width = NoImage_width;
  766.         img_info->height = NoImage_height;
  767.         Img = NoImage(hw);
  768.     }
  769.     else
  770.     {
  771.         XPutImage(XtDisplay(hw), Img, hw->drawGC, tmpimage, 0, 0,
  772.             0, 0, img_info->width, img_info->height);
  773.         XDestroyImage(tmpimage);
  774.     }
  775.  
  776.         /* Caught by Purify; should be OK. */
  777.         free((char *)Mapping);
  778.  
  779.     return(Img);
  780. #endif /* _AMIGA */
  781.     return NULL;
  782. }
  783.  
  784.